using System;
using System.IO;

public class FileLoader
{

    public static byte[] ReadBinFile(string path)
    {
        BinaryReader br;
        FileStream fs = new FileStream(path, FileMode.Open);
        byte[] b;
        try
        {
            br = new BinaryReader(fs);
        }
        catch (IOException e)
        {
            Console.WriteLine(e.Message + "\n Cannot open file.");
            return null;
        }
        try
        {
            b = br.ReadBytes((int)fs.Length);
        }
        catch (IOException e)
        {
            Console.WriteLine(e.Message + "\n Cannot read from file.");
            return null;
        }
        br.Close();
        return b;
    }

    #region 读文件
    /****************************************
     * 函数名称：ReadFile
     * 功能说明：读取文本内容
     * 参    数：Path:文件路径
     * 调用示列：
     *           string Path = Server.MapPath("Default2.aspx");      
     *           string s = EC.FileObj.ReadFile(Path);
    *****************************************/
    /// <summary>
    /// 读文件
    /// </summary>
    /// <param name="Path">文件路径</param>
    /// <returns></returns>
    public static string ReadFile(string Path)
    {
        string s = "";
        if (!System.IO.File.Exists(Path))
            s = "不存在相应的目录";
        else
        {
            StreamReader f2 = new StreamReader(Path, System.Text.Encoding.GetEncoding("gb2312"));
            s = f2.ReadToEnd();
            f2.Close();
            f2.Dispose();
        }

        return s;
    }
    #endregion
}